// 最大搜索筛选框超过三条显示更多选项
function showListMoreOrNot(){
    let screenList = document.getElementsByClassName('screenList')
    let ListExpand = document.getElementsByClassName('ListExpand')[0]
    let ListCollaps = document.getElementsByClassName('ListCollaps')[0]
    let searchScreenListCtn = document.getElementsByClassName('searchScreenListCtn')[0]
    let searchScreenList = document.getElementsByClassName('searchScreenList')
    // console.log(screenList.length);
    if(screenList.length>3){
        ListCollaps.classList.add('showOrNot')
        for(let i= 3; i<screenList.length;i++){
            // 三条以上筛选情况默认不显示
            screenList[i].classList.add('showOrNot')
            // 监听点击更多选项，出现不显示的筛选
            ListExpand.addEventListener('click', function(){
                screenList[i].classList.remove('showOrNot')
                ListExpand.classList.add('showOrNot')
                ListCollaps.classList.remove('showOrNot')
                // 监听点击收起，收起原本不显示的筛选情况
                ListCollaps.addEventListener('click', function(){
                    screenList[i].classList.add('showOrNot')
                    ListCollaps.classList.add('showOrNot')
                    ListExpand.classList.remove('showOrNot')
                })
            })
        }            
    }else{
        ListExpand.classList.add('showOrNot')
        ListCollaps.classList.add('showOrNot')
    }
}
showListMoreOrNot()

// 每一条筛选条件里边两行及以上显示更多
function singleShowMore(){
    let screenList = document.getElementsByClassName('screenList')
    let screenListContent =document.getElementsByClassName('screenListContent')
    let operationMore = document.getElementsByClassName('operationMore')
    // if(screenListContent.cl)
    //clientHeight包括content与内边距
    // console.log(screenList.clientHeight);
    // console.log(screenListContent.length);
    for(let i = 0; i<screenListContent.length; i++){
        if(screenListContent[i].clientHeight>59){
            operationMore[i].style.opacity = '1'
            // screenList[i].style.overflow = 'hidden'
        }else{
            operationMore[i].style.opacity = '0'
        }
    }   
}
// singleShowMore()

//点击多选，每个筛选上边显示复选框
// function checkBox(){
//     let operationMultiple = document.getElementsByClassName('operationMultiple')
//     let checkbox = document.getElementsByClassName('checkbox')
//     let detailDataLi = document.getElementsByClassName('detailDataLi')
//     console.log(detailDataLi.length);
//     // for(let i =0 ; i<operationMultiple.length; i++){
//     //     checkbox.style.display='none'
//     //     console.log(detailDataLi.length);
//     //     // operationMultiple[i].addEventListener('click', function(){
//     //     //     for(let j=0; i<detailDataLi.length; j++){
//     //     //         checkbox[j].style.display='block'
//     //     //     }
//     //     // })
//     // }
//     // operationMultiple.addEventListener('click', function(){
        
//     // })
// }
// // checkBox()

//点击确定的小分类出现确定取消按钮
function checkBox(){
    let detailDataLi =document.getElementsByClassName('detailDataLi')
    let detailData = document.getElementsByClassName('detailData')
    console.log(detailData.length);
    console.log(detailDataLi.length);
    for(let i = 0; i <detailData.length; i++){
        for(let j = 0; j<detailData[i].detailData.length; i++){
            
        }
    }
    
}
// checkBox()

//价格区间，获取焦点自动显示确定
function focusSure(){
    let priceStart = document.getElementById('priceStart')
    let priceEnd = document.getElementById('priceEnd')
    let sortSelectInner = document.getElementsByClassName('sortSelectInner')[0]
    let sortBtnI = document.getElementsByClassName('sortBtnI')[0]
    priceStart.onfocus = function(){
        // sortSelectInner.style.border = '1px solid #c8c8c8'
        // sortSelectInner.style.backgroundColor = '#fff'
        sortSelectInner.classList.add('sortSelectInnerTwo')
        sortBtnI.style.opacity = '1'
    }
    priceStart.onblur = function(){
        // sortSelectInner.removeAttribute('border')
        // sortSelectInner.removeAttribute('backgroundColor')
        sortSelectInner.classList.remove('sortSelectInnerTwo')
        sortBtnI.style.opacity = '0'
    }
    priceEnd.onfocus = function() {
        sortSelectInner.classList.add('sortSelectInnerTwo')
        sortBtnI.style.opacity = '1'
    }
    priceEnd.onblur = function(){
        sortSelectInner.classList.remove('sortSelectInnerTwo')
        sortBtnI.style.opacity = ''
    }
}
focusSure()

//搜索内容
var strHref =  document.location.toString()
console.log(strHref);
var index = strHref.indexOf('?')+1;
strHref = strHref.substring(index)
var arrAnd = strHref.split('&')
var obj = {}
for(let i = 0; i< arrAnd.length ; i++){
    let str1 = arrAnd[i].split('=')[0]
    let str2 = arrAnd[i].split('=')[1]
    obj[str1] = str2
}
// console.log(obj);
function searchBody(){
    axios({
        url:'/home/search/getAllLikeHome',
        method:'GET',
        params:{
            content:obj.content,
            setting:obj.setting
        }
    })
    .then(data =>{
        console.log(obj.content);
        console.log(decodeURIComponent(obj.setting));
        console.log(data);
        // console.log(data.data.data.data[0].length);
            let searchAllFinal = document.getElementsByClassName('searchAllFinal')[0]
            searchAllFinal.innerHTML = ``
            for(let i = 0; i<data.data.data.data[0].length; i++){
                searchAllFinal.innerHTML += `
                <div class="searchAllFinalItem">
                    <a href="/home/productDetail?goodsId=${data.data.data.data[0][i].goodsId}&shopId=${data.data.data.data[0][i].shopId}">
                        <div class="finalItemImg">
                            <img src="${data.data.data.data[0][i].cover}" alt="">
                        </div>
                        <h2>${data.data.data.data[0][i].goodsName}
                        </h2>
                    </a>
                    <p>￥${data.data.data.data[0][i].goodsPrice}</p>
                </div>
                `
            }
        document.getElementsByClassName('searchInput')[0].value = decodeURIComponent(obj.content)
        document.getElementById('priceStart').value =''
        document.getElementById('priceEnd').value =''
    })
    .catch(err => {
        console.log(err);
    })
}
searchBody()


// var strHref = document.location.toString();
// console.log(strHref);//打印出URL
// var intPos = strHref.indexOf("?")+1;
// // var strRight = strHref.substr(intPos + 1); //获取到右边的参数部分
// strHref = strHref.substring(intPos)
// var arr = strHref.split('&')
// var obj = {}
// for(let i =0; i<arr.length; i++){
//     let str1 = arr[i].split('=')[0]
//     let str2 = arr[i].split('=')[1]
//     obj[str1] = str2
// }
// console.log(obj);
//根据金额查询
function moneySearch(){
    let priceStart =document.getElementById('priceStart')
    let priceEnd = document.getElementById('priceEnd')
    content = decodeURIComponent(obj.content)
    setting = decodeURIComponent(obj.setting)
    console.log(content);
    console.log(setting);
    axios({
        url:'/home/search/getGoodsByLimit',
        method:'GET',
        params:{
            content:content,
            setting:setting,
            start:priceStart.value,
            end:priceEnd.value
        }
    })
    .then(data => {
        console.log(data);
        let searchAllFinal =document.getElementsByClassName('searchAllFinal')[0]
        searchAllFinal.innerHTML = ''
        for(let i =0; i<data.data.data.data.length; i++){
            searchAllFinal.innerHTML += `
            <div class="searchAllFinalItem">
                <a href="/home/productDetail?goodsId=${data.data.data.data[i].goodsId}&shopId=${data.data.data.data[i].shopId}" target="_blank">
                    <div class="finalItemImg">
                        <img src="${data.data.data.data[i].cover}" alt="">
                    </div>
                    <h2>${data.data.data.data[i].goodsName}
                    </h2>
                </a>
                <p>￥${data.data.data.data[i].goodsPrice}</p>
            </div>
            `
        }

    })
    .catch(err =>{
        console.log(err);
    })
}